<?php
/*
 * 地区动作
 * @author     Mark <zhaody901@126.com>
 * @copyright  Copyright (c) 2013 lemon team
 * @version    $Id: fd5ea3853b3c966d8b91f8e7d2c01771a45f4493 $
 * @time       14-1-17 下午3:26
 */
require '../../common.inc.php';

$areaMap = array(
	'0' => 'prov',
	'1' => 'city',
	'2' => 'district',
	'3' => 'fourth',
);
if($action == 'init'){//选择传值初始化
	$area = $AREA[$areaid];
	if(!$area)$area['arrparentid']=0;
	$parentids = explode(',', $area['arrparentid']);
	$selectedids = array_merge($parentids, array($areaid));
	$return = array();
	foreach($selectedids as $k => $pid) {
		$returnKey = $areaMap[$k];
		$areas =  $db->getAll("select areaid as id,areaname as name  from ".$db->getPre()."area where parentid=".$pid);
		foreach($areas as $ck => $cv) {
			if (in_array($cv['id'], $selectedids)) {
				$areas[$ck]['selected'] = 1;
			}
		}
		$return[$returnKey] = $areas;
	}
	echo json_encode($return);
}elseif($action == 'child'){//返回子元素
	$parentid = intval($parentid);
	$areas =  $db->getAll("select areaid as id,areaname as name  from ".$db->getPre()."area where parentid=".$parentid);
	echo json_encode(array('areas'=>$areas));
}

